package njit.mykafka;
import java.util.Properties;
import org.apache.kafka.clients.producer.*;
public class SimpleProducer3 {
	public static long start;
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost:9092");
        props.put("retries", 0);
        props.put("linger.ms", 1);
        props.put("acks", "all");
        props.put("batch.size", 16384);
        props.put("producer.type", "sync");
        props.put("buffer.memory", 333554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        Producer<String, String> producer = new KafkaProducer<String, String>(props);
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 100; i++)
            builder.append("" + i + ",");
        for (int i = 0; i < 5; i++) {
            ProducerRecord<String, String> rec = new ProducerRecord<String, String>("my-replicated-topic",
                    Integer.toString(i), "www-" + i);
            producer.send(rec, new Callback() {
                public void onCompletion(RecordMetadata arg0, Exception arg1) {
                    System.out.println("receiveed ack:" + (System.currentTimeMillis() - start));
                }
            });
            start = System.currentTimeMillis();
        }
        producer.close();
    }
}
